﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Silverlight.Navigation.Favorites;

namespace Silverlight.Navigation.Controls
{
    public partial class AddToFavorites : ChildWindow
    {
        #region Constructors

        public AddToFavorites()
        {
            InitializeComponent();
        }

        public AddToFavorites(string uri)
            : this()
        {
            this.UriValueTextBlock.Text = uri;
            this.NameTextBox.Text = uri;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The favorite item.
        /// </summary>
        public FavoriteItem FavoriteItem { get; set; }

        #endregion

        #region Event Handlers

        private void NameTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.AddButton.IsEnabled = !string.IsNullOrEmpty(this.NameTextBox.Text);
        }

        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            this.FavoriteItem = new FavoriteItem { Name = this.NameTextBox.Text, Uri = this.UriValueTextBlock.Text };
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        #endregion
    }
}

